package com.chaoyi.controller.ifs;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.chaoyi.model.Appointment;
import com.chaoyi.service.AppointmentService;
import com.chaoyi.util.PageUtil;
/**
 * 弹幕和在线用户接口
 * @author wbf
 */
@Controller
@RequestMapping("/appointmentIfs")
public class AppointmentIfsController {
	@Resource
	AppointmentService appointmentService;
	/**
	 * 返回数据list
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("getAppointmentList")
	@ResponseBody
	public JSONObject getBarrageAndUserList(HttpServletRequest request, HttpServletResponse response){
		response.setHeader("Access-Control-Allow-Origin", "*");
		JSONObject json = new JSONObject();
		int page = 0;
		int pageSize = 0;
		try {
			page = Integer.parseInt(request.getParameter("page"));
			pageSize = Integer.parseInt(request.getParameter("pageSize"));
		} catch (Exception e) {
			page = 1;
			pageSize = 20;
		}
		if (page < 0) {
			page = 1;
		}
		if (pageSize < 0 || pageSize > 20) {
			pageSize = 20;
		}
		List<Appointment> list = appointmentService.findList(PageUtil.getOffset(page, pageSize)+"",pageSize+"");
		json.put("rows", list);
		return json;
	}
}
